#!/usr/bin/env python
# coding: utf-8
import os
import jpype


class P2JPort(object):

    @staticmethod
    def get_cd():
        jarpath = os.path.join(os.path.abspath("."),
                               "/Users/tianze/Code/java/schedulerflashbuy/target/timeUntilDropBuy-jar-with-dependencies.jar")

        # 获取jvm 的文件路径
        jvmPath = jpype.getDefaultJVMPath()

        # 开启jvm
        jpype.startJVM(jvmPath, "-ea", "-Djava.class.path=%s" % (jarpath))

        # ②、加载java类（参数是java的长类名）
        javaClass = jpype.JClass("com.comic.core.P2JPort")

        # 实例化java对象
        # javaInstance = javaClass()

        # ③、调用java方法，由于我写的是静态方法，直接使用类名就可以调用方法
        x_kpsdk_cd = javaClass.getX_kpsdk_cd()
        print("x_kpsdk_cd", x_kpsdk_cd)
        # ④、关闭jvm
        jpype.shutdownJVM()

        return x_kpsdk_cd


if __name__ == '__main__':
    P2JPort.get_cd()
